import Vue from 'vue'

import Cookies from 'js-cookie'

import Element from 'element-ui'
import VueI18n from 'vue-i18n'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN' // 中文
import enLocale from 'element-ui/lib/locale/lang/en'    // 英文
import jaLocale from 'element-ui/lib/locale/lang/ja' // 日文
import './assets/styles/element-variables.scss'

import '@/assets/styles/index.scss' // global css
import '@/assets/styles/ruoyi.scss' // ruoyi css
import App from './App'
import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins
import { download } from '@/utils/request'

import './assets/icons' // icon
import './permission' // permission control
import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi"

// 全局方法挂载
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.$eventBus = new Vue()

Vue.use(directive)
Vue.use(plugins)
Vue.use(VueI18n)
console.log('window.$globalConfig', window.$globalConfig)
// 创建 i18n 实例
const i18n = new VueI18n({
  locale: window.$globalConfig.language || 'ja', // 默认语言
  messages: {
    'zh-CN': {
      ...zhLocale,      // Element UI 中文语言包
      ...window.$globalConfig.locale['zh-CN']
    },
    'en': {
      ...enLocale,      // Element UI 英文语言包
      ...window.$globalConfig.locale.en
    },
    'ja': {
      ...jaLocale,      // Element UI 日文语言包
      ...window.$globalConfig.locale.ja
    }
  }
})

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */

Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})
// 关键！配置 Element 使用 vue-i18n
Vue.use(Element, {
  i18n: (key, value) => i18n.t(key, value)
})

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  i18n,
  store,
  render: h => h(App)
})
